// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf

#ifndef MGCGEOMETRY_H
#define MGCGEOMETRY_H

#include "MgcSpatial.h"
#include "MgcColor.h"
#include "MgcVector2.h"


class MgcGeometry : public MgcSpatial
{
    MgcDeclareRTTI;
    MgcDeclareStream;

public:
    virtual ~MgcGeometry ();

    // vertex access
    unsigned int GetVertexQuantity () const;
    MgcVector3& Vertex (unsigned int uiV);
    const MgcVector3& Vertex (unsigned int uiV) const;
    MgcVector3* Vertices ();
    const MgcVector3* Vertices () const;

    // normal vector access
    MgcVector3& Normal (unsigned int uiV);
    const MgcVector3& Normal (unsigned int uiV) const;
    MgcVector3* Normals ();
    const MgcVector3* Normals () const;

    // color access
    MgcColor& Color (unsigned int uiV);
    const MgcColor& Color (unsigned int uiV) const;
    MgcColor* Colors ();
    const MgcColor* Colors () const;

    // texture coordinate access
    MgcVector2& Texture (unsigned int uiV);
    const MgcVector2& Texture (unsigned int uiV) const;
    MgcVector2* Textures ();
    const MgcVector2* Textures () const;

    // bounding sphere access
    MgcBound& ModelBound ();
    const MgcBound& ModelBound () const;

    // geometric updates
    virtual void UpdateModelBound ();
    virtual void UpdateWorldBound ();
    virtual void UpdateModelNormals ();

    // reallocate any nonnull arrays
    void Reconstruct (unsigned int uiVertexQuantity);

    // The reconstruction allows you to change only individual arrays.  You
    // do this by passing in the current array pointers for any arrays you
    // want to preserve.
    void Reconstruct (unsigned int uiVertexQuantity, MgcVector3* akVertex,
        MgcVector3* akNormal, MgcColor* akColor, MgcVector2* akTexture);

protected:
    // Construction and destruction.  MgcGeometry accepts responsibility for
    // deleting the input arrays.
    MgcGeometry (unsigned int uiVertexQuantity, MgcVector3* akVertex,
        MgcVector3* akNormal, MgcColor* akColor, MgcVector2* akTexture);

    MgcGeometry ();

    // render state update
    virtual void UpdateRenderState (MgcRenderState* apkState[]);

    // drawing
    virtual void Draw (MgcRenderer& rkRenderer);

    // vertices and attributes
    unsigned int m_uiVertexQuantity;
    MgcVector3* m_akVertex;
    MgcVector3* m_akNormal;
    MgcColor* m_akColor;
    MgcVector2* m_akTexture;

    // model bound
    MgcBound m_kBound;

    // render state
    MgcRenderStatePtr m_aspkState[MgcRenderState::RS_MAX_STATE];
};

MgcSmartPointer(MgcGeometry);
MgcRegisterStream(MgcGeometry);
#include "MgcGeometry.inl"

#endif
